package com.gt.queue;

import com.gt.common.QueueConstant;
import com.gt.notify.TestNotifyAndAdd;
import com.gt.service.debug.DebugService;
import com.gt.service.project.ProjectService;
import com.gt.service.projectJsdebug.ProjectJsdebugService;
import com.gt.service.projectJsdebugDetails.ProjectJsdebugDetailsService;
import com.gt.service.user.UserService;
import com.netflix.discovery.converters.Auto;
import org.apache.log4j.Logger;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * 消息消费者,监听 QueueConstant.DEBUG_QUEUE队列
 */
@Component
@RabbitListener(queues = QueueConstant.DEBUG_QUEUE)
public class RbReceiver {

    private static Logger logger = Logger.getLogger(RbReceiver.class);

    @Autowired
    private ProjectJsdebugService projectJsdebugService;
    @Autowired
    private ProjectJsdebugDetailsService projectJsdebugDetailsService;
    @Autowired
    private ProjectService projectService;
    @Autowired
    private UserService userService;
    @Autowired
    private JavaMailSender javaMailSender;
    @Value("${spring.mail.sender}")
    private String sender;
    @Autowired
    private DebugService debugService;

    //添加bug
    static Executor bugAdd = Executors.newCachedThreadPool();

    @RabbitHandler
    public void process(HashMap<String, Object> msg){
        logger.info("rabbitMq Has received from " + QueueConstant.DEBUG_QUEUE + ", msg: " + msg);
        //数据持久化
//        bugAdd.execute(new TestNotifyAndAdd(msg, projectService, projectJsdebugService, projectJsdebugDetailsService, userService, javaMailSender, sender));
        bugAdd.execute(new TestNotifyAndAdd(msg, debugService));
    }
    @RabbitHandler
    public void process(String msg){
        logger.info("rabbitMq Has received from " + QueueConstant.DEBUG_QUEUE + ", msg: " + msg);
    }
}
